/* 
This do file produces online appendix tables associated with the article: 
Wood, T, Hoy, C & Pryke, J "The effect of geostrategic competition 
on public attitudes to aid", Journal of Experimental Political Science.

This do file is focused on the AUSTRALIAN DATA.

Please email all questions to: terence.wood@anu.edu.au/terencewoodnz@gmail.com

First creates balance table for Australia (control and each treatment group),
which shows how well balanced groups are across key sociodemographic & political
traits.

Second runs alternate regression models for Australian questions.

This is done by question/dependent variable of interest, to produce full table 
of results for the question.
	The full table of results for the question contains:
	OLS no controls;
	Logistic bivariate;
	Logistic with full controls; 
	&
	Multinomial logistic (with and without controls). (Note that mlogit results
	are placed in their own table).
	
All tables are output into a single rtf file.

Do file coded in Stata version 14. 

You need to install the estout package before running this code:
http://repec.sowi.unibe.ch/stata/estout/	

You will need to install the ietoolkit package before running this code:
https://blogs.worldbank.org/impactevaluations/ie-analytics-introducing-ietoolkit
*/

********************************************************************************
*****************************Preliminaries**************************************
********************************************************************************

set more off

cd "ENTER YOUR WORKING DIRECTORY HERE"

use "1 Australia data JEPS FINAL", clear

********************************************************************************
******************************Balance Table*************************************
********************************************************************************

//Create temporary political variable indicating right wing preference
gen right = .
replace right = 0 if party==1
replace right = 1 if party==2
replace right = 1 if party==3
replace right = 0 if party==4

//Create temporary variable for date of survey
gen wave = .
replace wave = 0 if survey_date == 1
replace wave = 1 if survey_date == 2

//Create balance table
iebaltab urban over_fifty male academic income_per_person right wave, ///
grpvar(treatment_group) save(China_Balance_Australia)

//Tidy up
drop right
drop wave


********************************************************************************
**************************Full Regression Models********************************
********************************************************************************

**************************Attitudes to aid volume*******************************


estimates clear

****Simple OLS to test means (no controls) between treatment groups
qui reg too_much_aid i.treatment_group
	estimates store lv, title("Too much aid (OLS)")

****Logit on "too much aid" to compare bivariate model with model with controls

//Basic model no controls
qui logit too_much_aid i.treatment_group 
	estimates store lvsimple, title("Too much aid (logit)")

//Model full controls	
qui logit too_much_aid i.treatment_group ///
	i.urban i.over_fifty i.male i.party_simple i.academic ///
	income_per_person i.survey_date
	estimates store lvfull, title("Too much aid (logit w controls)")

//Table of results	
esttab lv lvsimple lvfull ///
using A_Aus_results.rtf, replace b(2) se(2) ///
label nonumber mtitle nobase starlevel(* 0.1 ** 0.05 *** 0.01) ///
nogaps title("Too much aid")


****Mlogit to study impact of treatments across all response categories
estimates clear

//simple model, no controls
qui mlogit aid_vol_simple i.treatment_group

//Predicted marginal effects of change between control and treatment groups
qui margins, dydx(treatment_group) atmeans post fvlabel
estimates store mvsimple, title("No controls")

//model with controls
qui mlogit aid_vol_simple i.treatment_group i.urban i.over_fifty i.male ///
i.party_simple i.academic income_per_person i.survey_date

//Predicted marginal effects of change between control and treatment groups
qui margins, dydx(treatment_group) atmeans post
estimates store mvfull, title("With controls")

//Table of predicted values
esttab mvsimple mvfull ///
using A_Aus_results.rtf, append b(2) se(2) ///
label nonumber mtitle nobase noomitted starlevel(* 0.1 ** 0.05 *** 0.01) ///
nogaps eqlabels("Measured" "Forceful") ///
coeflabels(1._predict  "Too much aid" 2._predict  "About right" 3._predict  "Too little aid") ///  
title("Aid volume (multinomial logistic)")

****Tidy up
estimates clear



**************************Attitudes to Pacific Focus****************************

estimates clear

****Simple OLS to test means (no controls) between treatment groups
qui reg more_to_pac i.treatment_group
	estimates store op, title("More Pacific (OLS)")

	
****Logit on "more focus on pacific" to compare bivariate with model with controls

//Simple model
qui logit more_to_pac i.treatment_group 
	estimates store lpsimple, title("More Pacific (logit)")

//Controls included	
qui logit more_to_pac i.treatment_group ///
	i.urban i.over_fifty i.male i.party_simple i.academic ///
	income_per_person i.survey_date
	estimates store lpfull, title("More Pacific (logit w controls)")
	
esttab op lpsimple lpfull ///
using A_Aus_results.rtf, append b(2) se(2) ///
label nonumber mtitle nobase starlevel(* 0.1 ** 0.05 *** 0.01) ///
nogaps title("More to Pacific")


****Mlogit to study impact of treatments across all response categories

estimates clear

//Create version of full Pacific variable with don't know coded as missing
//(in original data, in categorical variable don't know is 4)
clonevar pac_dk_gone= aid_pacific_focus
replace pac_dk_gone=. if pac_dk_gone==4

//Bivariate mlogit
qui mlogit pac_dk_gone i.treatment_group

//Predicted marginal effects of change between control and treatment groups
qui margins, dydx(treatment_group) atmeans post fvlabel
estimates store mpsimple, title("No controls")


//Mlogit with controls
qui mlogit pac_dk_gone i.treatment_group i.urban i.over_fifty i.male ///
i.party_simple i.academic income_per_person i.survey_date

//Predicted marginal effects of change between control and treatment groups
qui margins, dydx(treatment_group) atmeans post
estimates store mpfull, title("With controls")

//Produce table of results manually labelling values for each category
esttab mpsimple mpfull ///
using A_Aus_results.rtf, append b(2) se(2) ///
label nonumber mtitle nobase noomitted starlevel(* 0.1 ** 0.05 *** 0.01) ///
nogaps eqlabels("Measured" "Forceful") ///
coeflabels(1._predict "More to Pacific" 2._predict  "Same" 3._predict  "Less to Pacific") ///
title("Share to pacific (multinomial logistic)")  

****Tidy up
estimates clear
drop pac_dk_gone


**************************Attitudes to Aid Purpose****************************

****Simple OLS to test means (no controls) between treatment groups
qui reg favour_aus i.treatment_group
	estimates store og, title("Favour Australia (OLS)")

	
****Logit on "more geostrategic" to compare bivariate with model with controls	
qui logit favour_aus i.treatment_group 
	estimates store lgsimple, title("Favour Australia (logit)")
	
qui logit favour_aus i.treatment_group ///
	i.urban i.over_fifty i.male i.party_simple i.academic ///
	income_per_person i.survey_date
	estimates store lgfull, title("Favour Australia (logit w controls)")
	
esttab og lgsimple lgfull ///
using A_Aus_results.rtf, append b(2) se(2) ///
label nonumber mtitle nobase starlevel(* 0.1 ** 0.05 *** 0.01) ///
nogaps title("Favour aid used to advance Australian Interests")

estimates clear


****Mlogit to study impact of treatments across all response categories

//Create a simplified purpose categorical variable
gen simple_purpose=.
replace simple_purpose=1 if favour_aus==1
replace simple_purpose=2 if favour_poor==1
label define splab 1 "Australia" 2 "Poor"
label values simple_purpose splab

//Bivariate mlogit
qui mlogit simple_purpose i.treatment_group

//Predicted marginal effects of change between control and treatment groups
qui margins, dydx(treatment_group) atmeans post fvlabel
estimates store mpsimple, title("No controls")

//mlogit with controls
qui mlogit simple_purpose i.treatment_group i.urban i.over_fifty i.male ///
i.party_simple i.academic income_per_person i.survey_date

//Predicted marginal effects of change between control and treatment groups
qui margins, dydx(treatment_group) atmeans post
estimates store mpfull, title("With controls")

//Produce table of results manually labelling values for each category
esttab mpsimple mpfull ///
using A_Aus_results.rtf, append b(2) se(2) ///
label nonumber mtitle nobase noomitted starlevel(* 0.1 ** 0.05 *** 0.01) ///
nogaps eqlabels("Measured" "Forceful") ///
coeflabels(1._predict "Favour Australia" 2._predict  "Favour poor") ///
title("Aid help Australia or help poor (multinomial logistic)")  


****Tidy up
estimates clear
drop simple_purpose
label drop splab

